package com.koron.sinoprobe.web.ledger.service.impl;

import com.koron.common.core.config.ThreadLocalContext;
import com.koron.common.core.util.CodeTools;
import com.koron.sinoprobe.web.common.CommonUtils;
import com.koron.sinoprobe.web.ledger.bean.entity.SpMemorabilia;
import com.koron.sinoprobe.web.ledger.bean.query.SpMemorabiliaQuery;
import com.koron.sinoprobe.web.ledger.bean.vo.SpMemorabiliaVO;
import com.koron.sinoprobe.web.ledger.mapper.SpMemorabiliaMapper;
import com.koron.sinoprobe.web.ledger.service.SpMemorabiliaService;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author twcao
 * @title: SpMemorabiliaServiceImpl
 * @projectName GDH_EAM_V2
 * @description: 专项项目-大事记
 * @date 2021/12/1319:59
 */
@Service
public class SpMemorabiliaServiceImpl implements SpMemorabiliaService {

    @Override
    @TaskAnnotation("queryById")
    public SpMemorabilia queryById(SessionFactory factory, String id) {
        SpMemorabiliaMapper mapper = factory.getMapper(SpMemorabiliaMapper.class);
        return mapper.queryById(id);
    }

    @Override
    @TaskAnnotation("queryList")
    public List<SpMemorabiliaVO> queryList(SessionFactory factory, SpMemorabiliaQuery query) {
        SpMemorabiliaMapper mapper = factory.getMapper(SpMemorabiliaMapper.class);
        return mapper.queryList(query);
    }

    @Override
    @TaskAnnotation("saveOrUpdate")
    public SpMemorabilia saveOrUpdate(SessionFactory factory, SpMemorabilia bean) {
        Assert.notNull(bean, "项目合同不能为空");
        Assert.hasText(bean.getProjectId(), "项目id不能为空");
        CommonUtils.update(bean, ThreadLocalContext.get());
        bean.setId(StringUtils.isEmpty(bean.getId()) ? CodeTools.getCode32() : bean.getId());
        SpMemorabiliaMapper mapper = factory.getMapper(SpMemorabiliaMapper.class);
        mapper.saveOrUpdate(bean);
        return bean;
    }

    @Override
    @TaskAnnotation("deleteById")
    public Boolean deleteById(SessionFactory factory, String id) {
        SpMemorabiliaMapper mapper = factory.getMapper(SpMemorabiliaMapper.class);
        return mapper.deleteById(id) > 0;
    }
    
}
